function sinister_turn()

    Attack.act_aseq( 0, "happy" )
   	local ragemin = 0
   	local rnd=Game.Random(0,100)
   	local rage = Logic.cur_lu_item( "rage", "count" )
      	
    	      	    
	if rnd < 11 then
		local attqua=math.floor(rage/3)
		if rage <=0 then
			attqua = 1
		end		
		local kriqua=math.floor((rage*3)+20)
		Attack.atom_spawn(0,0, "effect_demonfury")
		Attack.atom_spawn(0,0, "effect_tbm2")
		Attack.act_ap(0, Attack.act_ap(0) + 3)
  		Attack.act_reload(0)
                	Attack.act_charge(0,0)
		Attack.act_del_spell( 0, "spell_berserker" )
    		Attack.act_apply_spell_begin(0, "spell_berserker", 2, false )
               		Attack.act_apply_par_spell("attack", 0, attqua, 0, 2, false)
        		Attack.act_apply_par_spell("krit", 0, kriqua, 0, 2, false)
    		Attack.act_apply_spell_end()
		if Attack.act_size(0)<2 then 
			
			Attack.log("add_blog_sin_angry_1","name",blog_side_unit(0,0))
		else 
			
			Attack.log("add_blog_sin_angry_2","name",blog_side_unit(0,0))
		end 
    end
	

return true
end


function features_sinister(damage,addrage,attacker,receiver,minmax,userdata,hitbacking)

	
if (minmax == 0) and damage > 0 and Attack.atk_name() == "moveattack" and Attack.act_level(receiver) < 5 then
		local spread=46
		local spell=Game.CurLocRand(0,4)
		local rnd=Game.CurLocRand(1,100)
		if rnd < spread then
		Attack.atom_spawn(receiver,0,"hll_beholder_post")
			if spell == 1 then
				if Attack.act_enemy(receiver) and not Attack.act_feature(receiver,"mind_immunitet,undead,boss,pawn,plant,mech") then
					local bl = Attack.act_belligerent()
					if bl == 0 then bl = 4 end
					Attack.act_belligerent(receiver, bl)
					local spell = "spell_hypnosis"
					local moves = 2
					Attack.act_apply_spell_begin( receiver, spell, moves, false )
					Attack.act_apply_spell_end()
					Attack.atom_spawn(receiver, 0, "magic_hypnosis",Attack.angleto(receiver))
					Attack.act_damage_addlog(receiver,"add_blog_hypnosis_")
				end
			end
			if spell == 2 then
				if Attack.act_enemy(receiver) and not Attack.act_feature(receiver,"boss,pawn,mech") then
					Attack.act_del_spell(receiver,"effect_curse")
    					Attack.act_apply_spell_begin(receiver, "effect_curse", 2, false )
            					Attack.act_apply_par_spell( "moral", -2, 0, 0, 2, false)
    					Attack.act_apply_spell_end()
            					Attack.act_damage_addlog(receiver,"add_blog_curse_")
    					Attack.atom_spawn(receiver, 0, "effect_curse2",0,true)
						Attack.act_damage_addlog(receiver,"add_blog_curse_")
				end
  			end
			if spell == 3 then
				 if Attack.act_enemy(receiver) and not Attack.act_feature(receiver,"boss,pawn,plant,mech") then
					Attack.act_apply_spell_begin( receiver, "spell_plague", 2, false )
          					if Attack.act_race(receiver)=="undead" then
            						Attack.act_apply_par_spell( "moral", 2, 0, 0, 2, false)
          					else 
            						Attack.act_apply_par_spell( "health", 0, -60, 0, 2, false)
            						Attack.act_apply_par_spell("attack", 0, -10, 0, 2, false)
            						Attack.act_apply_par_spell("defense", 0, -10, 0, 2, false)
          					end
          					Attack.act_spell_param(receiver, "spell_plague", 2,2)
               					Attack.act_apply_spell_end()
        					Attack.atom_spawn(receiver, 1 , "magic_greenfly",Attack.angleto(receiver),true)
					Attack.act_damage_addlog(receiver,"add_blog_plague_")
					
				end
			end
		end
     
end
 

if (minmax==0) and damage > 0 and Attack.atk_name() == "skull" then
	
	Attack.atom_spawn(receiver,0, "effect_skullimpact")
	local fear=40
	local level=3
	local duration=2
	local special=0
	local rnd=Game.Random(0,100)+1
	if rnd<fear and Attack.act_level(receiver)<=level and not Attack.act_feature(receiver,"mind_immunitet,undead,golem,mech,plant,pawn,boss")  and Attack.get_custom_param("vamp")=="1" and Attack.act_hp(receiver) > 0  then
        Attack.act_apply_spell_begin( receiver, "effect_fear", duration, false )
        Attack.act_apply_par_spell("autofight", 1, 0, 0, duration, false)
        Attack.act_apply_spell_end()
		Attack.act_damage_addlog(receiver,"add_blog_fear_")
		Attack.atom_spawn(receiver, 0, "magic_scare", Attack.angleto(receiver),true)
		Attack.act_damage_addlog(receiver,"add_blog_fear_")

	end
	local cruel=30
	local rnd=Game.Random(0,100)+1
	if rnd<cruel and Attack.act_level(receiver)>level and not Attack.act_feature(receiver,"mind_immunitet,mech,pawn,boss,golem") and Attack.get_custom_param("vamp")=="1" and Attack.act_hp(receiver) > 0   then
		Attack.act_del_spell(receiver, "spell_crue_fate" )
    	Attack.act_apply_spell_begin( receiver, "spell_crue_fate", duration, false )
   		Attack.act_apply_spell_end()
        Attack.atom_spawn(receiver, 0, "magic_cruelfate", Attack.angleto(receiver))
		Attack.act_damage_addlog(receiver,"add_blog_sin_doom_")
	end
         
	if Attack.cell_need_resurrect(attacker) then
	   	if (Attack.act_enemy(receiver) and not (Attack.act_feature(receiver,"undead,golem,plant,pawn,mech"))) and Attack.get_custom_param("vamp")=="1" then
			Attack.atom_spawn(receiver,0,"effect_dismissal")

			local count_1 = Attack.act_size(attacker)
			local vamp = math.min(Attack.act_totalhp(receiver), damage)
			local hp1 = Attack.act_totalhp(attacker)
			Attack.act_resurrect(attacker, math.floor(vamp*.7))
			local count_2 = Attack.act_size(attacker)
			Attack.atom_spawn(attacker, 0, "effect_total_cure")
			local log_msg="add_blog_sin_vamp_"
			local resur=count_2-count_1
			local cura= Attack.act_totalhp(attacker) - hp1
			if count_2==count_1  then
				if Attack.act_size(receiver)<2 then 
				Attack.log("add_blog_sin_vamp_1","name",blog_side_unit(0,0),"special",cura)
				else
				Attack.log("add_blog_sin_vamp_2","name",blog_side_unit(0,0),"special",cura)
				end
			else
				if Attack.act_size(receiver)<2 then
								
				Attack.log("add_blog_sin_vamp_01","name",blog_side_unit(0,0),"special",resur)
				else
				Attack.log("add_blog_sin_vamp_02","name",blog_side_unit(0,0),"special",resur)
				end
			end
		end
	end
end	
    return damage,addrage
end


function summon_fireskeleton()
	local target = Attack.get_target()
	local quantity = 0
	local ragequa = 1
	local limit = Logic.cur_lu_item( "rage", "limit" )
	local drained = Logic.cur_lu_item( "rage", "count" )
	Logic.cur_lu_item( "rage", "count", 0)
	Game.ClearEffect( "rage" )
	--ragequa = math.floor(drained/4)
	ragequa = math.floor((drained/3)/(1+tonumber(drained)/100))
	----------------------------------------
	Attack.aseq_rotate(0,target)
	local dmgts = Attack.aseq_time(0)
	Attack.act_aseq( 0, "special" )
	Attack.atom_spawn(target, 2, "hll_priest_resur_cast")
	Attack.atom_spawn(target, 1, "hll_telein")
	dmgts = dmgts+Attack.aseq_time(0, "x")*2
	local nearest_dist, nearest_enemy, ang_to_enemy = 10e10, nil, 0
	for i=1,Attack.act_count()-1 do
		if Attack.act_enemy(i) then
			local d = Attack.cell_dist(target,i)
			if d < nearest_dist then nearest_dist = d; nearest_enemy = i; end
		end
	end
	if nearest_enemy ~= nil then ang_to_enemy = Attack.angleto(target, nearest_enemy) end
	-----------------------------------------	
	local count=Attack.act_size(0)*ragequa
	local unit_summon=""
	if drained < (limit/3) then 
		count=Attack.act_size(0)
		quantity=math.floor(Game.Random(20,45)*(1+tonumber(skill_power2("summonner",1)/100)))
		unit_summon="glaskeleton"
	else
		quantity=math.floor(Game.Random(2,4)*(1+tonumber(skill_power2("summonner",1)/100)))
		
		unit_summon="fireskeleton"
	end
	local count_summon=(count*quantity)
	local t = Attack.aseq_time(0) - .3
	Attack.act_spawn(target, 0, unit_summon, ang_to_enemy, count_summon)
    Attack.act_nodraw(target, true)
    local t = Attack.aseq_time(0) - .3
    Attack.act_animate(target, "respawn", t)
    Attack.act_nodraw(target, false, t)
    Attack.log_label("add_blog_summon_")
    Attack.log_special(count_summon) 
	if Attack.act_size(0)<2 then 
		if drained > 0 then
			Attack.log("add_blog_sin_ragedrain_1","name",blog_side_unit(0,0),"special",drained)
		end
	else 	
		if drained > 0 then	
			Attack.log("add_blog_sin_ragedrain_2","name",blog_side_unit(0,0),"special",drained)
		end
	end 
return true
end

function summon_venskeleton()
	local target = Attack.get_target()
	local quantity = 0
	local ragequa = 1
	local limit = Logic.cur_lu_item( "rage", "limit" )
	local drained = Logic.cur_lu_item( "rage", "count" )
	Logic.cur_lu_item( "rage", "count", 0)
	Game.ClearEffect( "rage" )
	ragequa = math.floor((drained/3)/(1+tonumber(drained)/100))
	-----------------------------------------
	Attack.aseq_rotate(0,target)
	local dmgts = Attack.aseq_time(0)
	Attack.act_aseq( 0, "special" )
	Attack.atom_spawn(target, 2, "hll_priest_resur_cast")
	Attack.atom_spawn(target, 1, "hll_telein")
	dmgts = dmgts+Attack.aseq_time(0, "x")*2
	local nearest_dist, nearest_enemy, ang_to_enemy = 10e10, nil, 0
	for i=1,Attack.act_count()-1 do
		if Attack.act_enemy(i) then
			local d = Attack.cell_dist(target,i)
			if d < nearest_dist then nearest_dist = d; nearest_enemy = i; end
		end
	end
	if nearest_enemy ~= nil then ang_to_enemy = Attack.angleto(target, nearest_enemy) end
	------------------------------------------	
	local count=Attack.act_size(0)*ragequa
	local unit_summon=""
	if drained < (limit/3) then 
		count=Attack.act_size(0)
		quantity=math.floor(Game.Random(20,45)*(1+tonumber(skill_power2("summonner",1)/100)))
		unit_summon="glaskeleton"
	else
		quantity=math.floor(Game.Random(2,4)*(1+tonumber(skill_power2("summonner",1)/100)))
		unit_summon="venskeleton"
		
	end
	local count_summon=(count*quantity)
	local t = Attack.aseq_time(0) - .3
	Attack.act_spawn(target, 0, unit_summon, ang_to_enemy, count_summon)
    Attack.act_nodraw(target, true)
    local t = Attack.aseq_time(0) - .3
    Attack.act_animate(target, "respawn", t)
    Attack.act_nodraw(target, false, t)
    Attack.log_label("add_blog_summon_")
    Attack.log_special(count_summon) 
	if Attack.act_size(0)<2 then 
		if drained > 0 then
			Attack.log("add_blog_sin_ragedrain_1","name",blog_side_unit(0,0),"special",drained)
		end
	else 	
		if drained > 0 then	
			Attack.log("add_blog_sin_ragedrain_2","name",blog_side_unit(0,0),"special",drained)
		end
	end 
return true
end
 
function summon_evil_book()
	local target = Attack.get_target()
	Attack.aseq_rotate(0,target)
	local dmgts = Attack.aseq_time(0)
	Attack.act_aseq( 0, "special" )
	Attack.atom_spawn(target, 3, "hll_priest_resur_cast")
	dmgts = dmgts+Attack.aseq_time(0, "x")*2
	local nearest_dist, nearest_enemy, ang_to_enemy = 10e10, nil, 0
	for i=1,Attack.act_count()-1 do
		if Attack.act_enemy(i) then
			local d = Attack.cell_dist(target,i)
			if d < nearest_dist then nearest_dist = d; nearest_enemy = i; end
		end
	end
	if nearest_enemy ~= nil then ang_to_enemy = Attack.angleto(target, nearest_enemy) end
	local count=Attack.act_size(0)
    local count_f=0
    local min_count,max_count=text_range_dec(Attack.get_custom_param("count"))
    local count_f=Game.CurLocRand(min_count*count*(2+tonumber(skill_power2("summonner",1)/100)),max_count*count*(2+tonumber(skill_power2("summonner",1)/100)))
	local unit_summon="evil_book"
    local count_summon=math.ceil(count_f/Attack.atom_getpar(unit_summon,"leadership"))
	local t = Attack.aseq_time(0) - .3
	Attack.act_spawn(target, 0, unit_summon, ang_to_enemy, count_summon)
    Attack.act_nodraw(target, true)
    local t = Attack.aseq_time(0) - .3
    Attack.act_animate(target, "appear", t)
    Attack.act_nodraw(target, false, t)
	Attack.log_label("add_blog_summon_")
    Attack.log_special(count_summon) 
	return true
end
  

  

